<template>
	<div class="bigDiv">
		<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="88px">
			<div class="topNav">
				<el-button type="text" icon="el-icon-plus" @click="defineProcess">创建</el-button>
				<el-button type="text" icon="el-icon-refresh" @click="resetQuery" style="float:right;">重置</el-button>
				<el-button type="text" icon="el-icon-search" @click="handleQuery" style="float:right;">搜索</el-button>
			</div>
			<el-form-item label="名称" prop="name">
				<el-input v-model="queryParams.name" placeholder="请输入名称" clearable size="small"
					@keyup.enter.native="handleQuery" />
			</el-form-item>
		</el-form>

		<el-table v-loading="loading" :data="Modeler" height="calc(100vh - 320px)">
			<el-table-column label="流程ID" align="center" prop="id" />
			<el-table-column label="流程KEY" align="center" prop="key" />
			<el-table-column label="流程名称" align="center" prop="name" />
			<el-table-column label="版本" align="center" prop="version" />
			<el-table-column label="部署时间" align="center" prop="deploymentTime" />
			<el-table-column label="部署ID" align="center" prop="deploymentId" />

			<el-table-column label="状态" align="center" prop="suspendState">
				<template slot-scope="scope">
					<span>{{ scope.row.suspendState!=1?'挂起':'激活'}}</span>
				</template>
			</el-table-column>
			<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
				<template slot-scope="scope">
					<el-button type="text" icon="el-icon-edit"
						@click="OnlineModificationProcess(scope.row)">查看
					</el-button>
					<el-button type="text" icon="el-icon-edit" @click="suspendOrActiveApply(scope.row)">
						{{scope.row.suspendState==1?'挂起':'激活'}}
					</el-button>

					<el-button type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除
					</el-button>
				</template>
			</el-table-column>
		</el-table>

		<pagination v-show="total > 0 " :total="total" :page.sync="queryParams.pageNum"
			:limit.sync="queryParams.pageSize" @pagination="getList" />

	</div>
</template>

<script>
	import {
		listDefinition,
		delDefinition,
		suspendOrActiveApply,
	} from "@/api/supplierActivity/definition";

	export default {
		name: "SupplierActIdGroup",
		data() {
			return {
				modelerUrl: "",
				modelVisible: false,
				// 遮罩层
				loading: true,
				// 非单个禁用
				single: true,
				// 非多个禁用
				multiple: true,
				// 显示搜索条件
				showSearch: true,
				// 总条数
				total: 0,
				// VIEW表格数据
				Modeler: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				src: "",
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					id: null,
					rev: null,
					name: null,
					type: null
				},
				upload: {
					// 是否显示弹出层（用户导入）
					open: false,
					// 弹出层标题（用户导入）
					title: "",
					// 是否禁用上传
					isUploading: false,
					// 设置上传的请求头部
					headers: '',
					// 上传的地址
					url: process.env.VUE_APP_BASE_API + "/supplier-activity/processDefinition/upload",
				},
			};
		},
		created() {
			this.getList();
		},
		methods: {
			/** 查询Definition列表 */
			getList() {
				this.loading = true;
				listDefinition(this.queryParams).then(response => {
					this.Modeler = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getList();
			},
			/** 重置按钮操作 */
			resetQuery() {
				this.resetForm("queryForm");
				this.handleQuery();
			},
			defineProcess() {
				localStorage.setItem("supplierActivityType", 0);
				this.$router.push({
					path: "/supplier_activiti?type=0"
				})
			},
			OnlineModificationProcess(data) {
				this.$router.push({
					path: "/supplier_activiti?type=1&deploymentId=" + data.deploymentId
				})
			},
			/** 删除按钮操作 */
			handleDelete(row) {
				this.$confirm('是否确认删除编号为"' + row.key + '"的数据项?', "警告", {
					confirmButtonText: "确定",
					cancelButtonText: "取消",
					type: "warning"
				}).then(function() {
					return delDefinition(row.deploymentId);
				}).then(() => {
					this.getList();
					this.msgSuccess("删除成功");
				}).catch(function() {});
			},
			suspendOrActiveApply(row) {
				var suspendOrActive = row.suspendState === '2' ? '激活' : '挂起';
				this.$confirm('确认要' + suspendOrActive + '流程定义吗?', "警告", {
					confirmButtonText: "确定",
					cancelButtonText: "取消",
					type: "warning"
				}).then(function() {
					var data = {
						"id": row.id,
						"suspendState": row.suspendState
					};
					return suspendOrActiveApply(data);
				}).then(() => {
					this.getList();
					this.msgSuccess("转换成功");
				}).catch(function() {});
			}
		}
	}
</script>

<style>
</style>
